home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_337 / cmanual / idcmp.lzh / IDCMP / Example6.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  5KB  |  160 lines

  1. /* Example6                                                    */
  2. /* This program explains how to use the IDCMP flag VANILLAKEY. */
  3.  
  4.  
  5.  
  6. #include <intuition/intuition.h>
  7.  
  8.  
  9.  
  10. struct IntuitionBase *IntuitionBase;
  11.  
  12.  
  13.  
  14. /* Declare a pointer to a Window structure: */ 
  15. struct Window *my_window;
  16.  
  17. /* Declare and initialize your NewWindow structure: */
  18. struct NewWindow my_new_window=
  19. {
  20.   50,             /* LeftEdge    x position of the window. */
  21.   25,             /* TopEdge     y positio of the window. */
  22.   320,            /* Width       320 pixels wide. */
  23.   100,            /* Height      100 lines high. */
  24.   0,              /* DetailPen   Text should be drawn with colour reg. 0 */
  25.   1,              /* BlockPen    Blocks should be drawn with colour r. 1 */
  26.   CLOSEWINDOW|    /* IDCMPFlags  We will recieve a message when the user */
  27.                   /*             selects the Close window gad.           */
  28.  
  29.   VANILLAKEY,     /*             We will also recieve a message whenever */
  30.                   /*             the user presses/releases a key.        */
  31.  
  32.   SMART_REFRESH|  /* Flags       Intuition should refresh the window. */
  33.   WINDOWCLOSE|    /*             Close Gadget. */
  34.   WINDOWDRAG|     /*             Drag gadget. */
  35.   WINDOWDEPTH|    /*             Depth arrange Gadgets. */
  36.   WINDOWSIZING|   /*             Sizing Gadget. */
  37.   ACTIVATE,       /*             The window should be Active when opened. */
  38.   NULL,           /* FirstGadget No gadgets connected to this window. */
  39.   NULL,           /* CheckMark   Use Intuition's default CheckMark. */
  40.   "PRESS MY KEYS",/* Title       Title of the window. */
  41.   NULL,           /* Screen      Connected to the Workbench Screen. */
  42.   NULL,           /* BitMap      No Custom BitMap. */
  43.   100,            /* MinWidth    We will not allow the window to become */
  44.   50,             /* MinHeight   smaller than 100 x 50, and not bigger */
  45.   400,            /* MaxWidth    than 400 x 200. */
  46.   200,            /* MaxHeight */
  47.   WBENCHSCREEN    /* Type        Connected to the Workbench Screen. */
  48. };
  49.  
  50.  
  51.  
  52. /**************************************************************************/
  53. /* Extra information:                                                     */
  54. /* Whenever the user presses/releases a key will we recieve a message.    */
  55. /* The Code part of the message contains the translated keykode (Default  */
  56. /* keymap used). (See Appendix * for more information about ASCII codes.) */
  57. /**************************************************************************/
  58.  
  59.  
  60.  
  61. main()
  62. {
  63.   /* Boolean variable used for the while loop: */
  64.   BOOL close_me;
  65.  
  66.   ULONG class;      /* IDCMP flag. */
  67.   USHORT code;      /* Code. */
  68.  
  69.   /* Pointer to an IntuiMessage structure: */
  70.   struct IntuiMessage *my_message;
  71.  
  72.  
  73.  
  74.   /* Before we can use Intuition we need to open the Intuition Library: */
  75.   IntuitionBase = (struct IntuitionBase *)
  76.     OpenLibrary( "intuition.library", 0 );
  77.   
  78.   if( IntuitionBase == NULL )
  79.     exit(); /* Could NOT open the Intuition Library! */
  80.  
  81.  
  82.  
  83.   /* We will now try to open the window: */
  84.   my_window = (struct Window *) OpenWindow( &my_new_window );
  85.   
  86.   /* Have we opened the window succesfully? */
  87.   if(my_window == NULL)
  88.   {
  89.     /* Could NOT open the Window! */
  90.     
  91.     /* Close the Intuition Library since we have opened it: */
  92.     CloseLibrary( IntuitionBase );
  93.  
  94.     exit();  
  95.   }
  96.  
  97.  
  98.  
  99.   /* We have opened the window, and everything seems to be OK. */
  100.  
  101.   printf("Press some keys!\n\n");
  102.  
  103.  
  104.  
  105.   close_me = FALSE;
  106.  
  107.   /* Stay in the while loop until the user has selected the Close window */
  108.   /* gadget: */
  109.   while( close_me == FALSE )
  110.   {
  111.     /* Wait until we have recieved a message: */
  112.     Wait( 1 << my_window->UserPort->mp_SigBit );
  113.  
  114.  
  115.     /* As long as we can collect messages successfully we stay in the */
  116.     /* while-loop: */
  117.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  118.     {
  119.       /* After we have successfully collected the message we can read */
  120.       /* it, and save any important values which we maybe want to check */
  121.       /* later: */
  122.       class = my_message->Class;         /* IDCMP flag. */
  123.       code = my_message->Code;           /* Code. */
  124.  
  125.  
  126.       /* After we have read it we reply as fast as possible: */
  127.       /* REMEMBER! Do never try to read a message after you have replied! */
  128.       /* (Some other process has maybe changed it.) */
  129.       ReplyMsg( my_message );
  130.  
  131.  
  132.       /* Check which IDCMP flag was sent: */
  133.       switch( class )
  134.       {
  135.         case CLOSEWINDOW:    /* The user selected the Close window gad. */
  136.                close_me=TRUE;
  137.                break;
  138.  
  139.         case VANILLAKEY:     /* The user pressed/released a key! */
  140.                /* Print out the translated keycode (as dec. and hex.): */
  141.                printf("Translated keycode: %6d(d) %6x(h)\n\n", code, code );
  142.                
  143.                break;
  144.       }
  145.     }
  146.   }
  147.  
  148.  
  149.  
  150.   /* Close the window: */
  151.   CloseWindow( my_window );
  152.  
  153.  
  154.  
  155.   /* Close the Intuition Library: */
  156.   CloseLibrary( IntuitionBase );
  157.   
  158.   /* THE END */
  159. }
  160.